from .air import Air
from .eventCenter import EventCenter
from pygame.sprite import Group
from collections import deque


class AirFactory(EventCenter):

    def __init__(self, screen):
        self.screen = screen
        self.airs = []
        self.eventMap = {

            'gameUpdate': self.update,
            'gameBlit': self.blitme,
            'createAir': self.createAir,
            'removeAir': self.removeAir,
                
        }

        self.createAir({})
        self.bindEvent()
        
    def createAir(self, event):
       
        air = Air(self.screen)
        self.airs.append(air)

    def removeAir(self, air):
        self.airs.remove(air)

    
    def update(self, event):
        
        for i,  item in enumerate(self.airs):
            item.update(event)

    
    def blitme(self, event):
        for item in self.airs:
            item.blitme(event)

    def bindEvent(self):

        for eventName, fn in self.eventMap.items():
            self.registered(eventName, fn)
            